package com.aubrey.threadDemo.create;

import java.util.Random;

public class ThreadLocalDemo2 {
	public static void main(String[] args) {
		ThreadLocal<Integer> tlocal1 = new ThreadLocal<>();
		tlocal1.set(0);
		
		for (int i = 0; i < 10; i++) {
			new Thread(()->{
				tlocal1.set(new Random().nextInt(10));
				System.out.println(Thread.currentThread().getName() +":" 
				+ tlocal1.get() );
			}).start();
		}
		
		while(Thread.activeCount() > 1)Thread.yield();
		System.out.println("main:"+tlocal1.get());
	}
}
